package com.bfly.mall.wechat.mp.service.message.event;

import com.alibaba.fastjson.JSONObject;
import com.bfly.mall.user.entity.User;
import com.bfly.mall.wechat.entity.WeChatMp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 推送事件消息处理
 *
 * @author 长沙商脉科技有限公司
 * @date 2021/1/7 20:36
 */
@Component
public class PushEventMsgHandler {

    private static final String SUBSCRIBE_EVENT = "subscribe";                        // 订阅
    private static final String UNSUBSCRIBE_EVENT = "unsubscribe";                    // 取消订阅
    private static final String LOCATION_EVENT = "location";                          // 上报地理位置事件
    private static final String CLICK_EVENT = "click";                                // 点击菜单
    private static final String SCANCODE_PUSH_EVENT = "scancode_push";                //扫码推事件
    private static final String SCANCODE_WAIT_MSG_EVENT = "scancode_waitmsg";         // 扫码推事件且弹出“消息接收中”提示框的事件推送
    private static final String PIC_SYS_PHOTO_EVENT = "pic_sysphoto";                // 弹出系统拍照发图的事件推送
    private static final String PIC_PHOTO_OR_ALBUM_EVENT = "pic_photo_or_album";    //  弹出拍照或者相册发图的事件推送
    private static final String PIC_WEI_XIN_EVENT = "pic_weixin";                  // 弹出微信相册发图器的事件推送
    private static final String LOCATION_SELECT_EVENT = "location_select";        // 弹出地理位置选择器的事件推送

    @Autowired
    private ClickEventMenuHandler clickEventMenuHandler;


    public String handle(WeChatMp mp, User user, JSONObject json) {
        String event = json.getString("Event").toLowerCase();
        String result = "";
        switch (event) {
            case SUBSCRIBE_EVENT:
                break;
            case UNSUBSCRIBE_EVENT:
                break;
            case LOCATION_EVENT:
                break;
            case CLICK_EVENT:
                // 响应文本/图片/图文/语音/视频/音乐消息
                result = clickEventMenuHandler.execute(json.getString("EventKey"), mp, user);
                break;
            case SCANCODE_PUSH_EVENT:
                break;
            case SCANCODE_WAIT_MSG_EVENT:
                break;
            case PIC_SYS_PHOTO_EVENT:
                break;
            case PIC_PHOTO_OR_ALBUM_EVENT:
                break;
            case PIC_WEI_XIN_EVENT:
                break;
            case LOCATION_SELECT_EVENT:
                break;
        }
        return result;
    }
}
